#※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
# File Name: call_entry.sh
# Author: GID5564
# Description:
# Created Time: 22/09/23-10:04:39
#※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
#! /bin/bash

function __api_init__(){
    #install_dependence
    export ENTRY_API="${PYLIB_PATH}/exa/image_handler.py"
}

function install_dependence(){
    local python_package="${PYLIB_PATH}/dependence.txt"
    [[ -s ${python_package} ]] && {
        msg "${BLUE}安装软件包及依赖:${RESET}"
        eval "${CMD_PIP_INSTALL} -r ${python_package}"
    }
    unset python_package
}


function jiugongge(){
    local op="JIUGONGGE"
    Msg "${BLUE}请输入要转换图片的完整路径: ${RESET}"
    read image

    [[ ! -s ${image} ]] && {
        error "${image}文件不存在!"
        return 1
    }
    
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "${image}不是一个有效的图片文件!"
        return 1
    fi
    
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在转换中……"
    #local ret=$(python3 ${ENTRY_API} ${op} ${image} ${save})
    
    local ret=$(invoke_image JiuGongGe ${image} ${save})

    if [[ ${ret} = "True" ]];then
        success "转换完成!"
    else
        error "转换失败!"
    fi
    unset ret
    unset image
    unset save
    unset ism
}

function wordcloud(){
    local op="WORDCLOUD"
    Msg "${BLUE}请输入一个文本文档完整路径(默认${YELLOW}wordcloud.txt${RESET}${BLUE}): ${RESET}"
    read txt
    if [[ -z ${txt} ]] || [[ ! -f ${txt} ]];then
        txt=${DATA_PATH}'/wordcloud.txt'
    fi
    Msg "${BLUE}请输入一个字体文件完整路径(默认${YELLOW}simhei.ttf${RESET}${BLUE}): ${RESET}"
    read font
    if [[ -z ${font} ]] || [[ ! -f ${font} ]];then
        font=${FONT_PATH}'/simhei.ttf'
    fi
    Msg "${BLUE}词云图宽(默认${YELLOW}300${RESET}${BLUE}): ${RESET}"
    read width
    local isn=$(IsNumber ${width})
    if [[ -z ${top} ]] || [[ ${isn} -ne 0 ]];then
        width=300
    fi
    Msg "${BLUE}词云图高(默认${YELLOW}450${RESET}${BLUE}): ${RESET}"
    read height
    local isn=$(IsNumber ${height})
    if [[ -z ${top} ]] || [[ ${isn} -ne 0 ]];then
        height=450
    fi
    Msg "${BLUE}词云图形状(图片，默认${YELLOW}None${RESET}${BLUE}): ${RESET}"
    read mask
    if [[ -z ${mask} ]];then
        mask="None"
    fi
    local ism=$(IsImage ${mask})
    if [[ ${ism} -ne 1 ]];then
        mask="None"
    fi
    Msg "${BLUE}词云图形背景色(默认${YELLOW}white${RESET}${BLUE}): ${RESET}"
    read color
    local isc=$(IsColorName ${color})
    if [[ -z ${color} ]] || [[ ${isc} -ne 0 ]];then
        color="white"
    fi
    Msg "${BLUE}词频最高的词数(默认${YELLOW}50${RESET}${BLUE}): ${RESET}"
    read top
    local isn=$(IsNumber ${top})
    if [[ -z ${top} ]] || [[ ${isn} -ne 0 ]];then
        top=50
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${txt} ${font} ${width} ${height} ${mask} ${color} ${top} ${save})
    if [[ ${ret} = "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ret
    
    unset op
    unset isn
    unset ism
    unset isc
    unset txt
    unset font
    unset width
    unset height
    unset mask
    unset color
    unset top
    unset save
}

function 2dcode(){
    local op="2DCODE"
    Msg "${BLUE}请输入二维码要展示的内容: ${RESET}"
    read content
    Msg "${BLUE}请输入二维码边长(默认为${RESET}${YELLOW}5${RESET}${BLUE}): ${RESET}"
    read size
    local isn=$(IsNumber ${size})
    if [[ -z ${size} ]] || [[ ${isn} -ne 0 ]];then
        size=5
    fi
    Msg "${BLUE}请输入背景图(默认为${RESET}${YELLOW}None${RESET}${BLUE}): ${RESET}"
    read image
    if [[ -z ${image} ]];then
        image="None"
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        image="None"
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${content} ${size} ${image} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ret
    unset op
    unset isn
    unset ism
    unset content
    unset size
    unset image
    unset save
}

function filter_embossment(){
    local op='EMBOSSMENT'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset save
    unset ret
}

function filter_carve(){
    local op='CARVE'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset save
    unset ret
}

function filter_convex_lens(){
    local op='CONVEXLENS'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset save
    unset ret
}

function filter_negative_film(){
    local op='NEGATIVEFILM'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset save
    unset ret
}

function filter_sketch(){
    local op='SKETCH'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    
    Msg "${BLUE}请输入模糊程度[1-100](默认为${RESET}${YELLOW}5${RESET}${BLUE}): ${RESET}"
    read sigmax
    local isn=$(IsNumber ${sigmax})
    if [[ -z ${sigmax} ]] || [[ ${isn} -ne 0 ]];then
        sigmax=5
    fi

    #内核大小
    Msg "${BLUE}请输入内核大小(默认为${RESET}${YELLOW}7${RESET}${BLUE}): ${RESET}"
    read ksize
    local isn=$(IsNumber ${ksize})
    if [[ -z ${ksize} ]] || [[ ${isn} -ne 0 ]];then
        ksize=7
    fi
    Msg "${BLUE}请输入锐化值[0-254](默认为${RESET}${YELLOW}10${RESET}${BLUE}): ${RESET}"
    read sharpen_value
    local isn=$(IsNumber ${sharpen_value})
    if [[ -z ${sharpen_value} ]] || [[ ${isn} -ne 0 ]];then
        sharpen_value=10
    fi

    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${sigmax} ${ksize} ${sharpen_value} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset isn
    unset op
    unset image
    unset sigmax
    unset ksize
    unset sharpen_value
    unset save
    unset ret
}

function filter_nostalgia(){
    local op='NOSTALGIA'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset save
    unset ret
}

function filter_illumination(){
    local op='ILLUMINATION'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    
    Msg "${BLUE}请输入光照强度(默认为${RESET}${YELLOW}200${RESET}${BLUE}): ${RESET}"
    read strength
    local isn=$(IsNumber ${strength})
    if [[ -z ${strength} ]] || [[ ${isn} -ne 0 ]];then
        strength=200
    fi
    
    Msg "${BLUE}请输入光照中心X点[0-1](默认为${RESET}${YELLOW}0.1${RESET}${BLUE}): ${RESET}"
    read Xcenter
    if [[ -z ${Xcenter} ]];then
        Xcenter=0.1
    fi
    if [[ ${Xcenter} -lt 0 ]]&&[[${Xcenter} -gt 1 ]];then
        Xcenter=0.1
    fi
    Msg "${BLUE}请输入光照中心Y点[0-1](默认为${RESET}${YELLOW}0.7${RESET}${BLUE}): ${RESET}"
    read Ycenter
    if [[ -z ${Ycenter} ]];then
        Ycenter=0.7
    fi
    if [[ ${Ycenter} -lt 0 ]]&&[[${Ycenter} -gt 1 ]];then
        Ycenter=0.7
    fi

    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${strength} ${Xcenter} ${Ycenter} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset isn
    unset op
    unset image
    unset strength
    unset Xcenter
    unset Ycenter
    unset save
    unset ret
}

function filter_flowingyear(){
    local op='FLOWINGYEAR'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入权重(默认为${RESET}${YELLOW}12${RESET}${BLUE}): ${RESET}"
    read weight
    local isn=$(IsNumber ${weight})
    if [[ -z ${weight} ]] || [[ ${isn} -ne 0 ]];then
        weight=12
    fi
    
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${weight} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset save
    unset ret
}

function filter_oilpaint(){
    local op='OILPAINT'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    
    Msg "${BLUE}请输入模板大小(默认为${RESET}${YELLOW}8${RESET}${BLUE}): ${RESET}"
    read bucksize
    local isn=$(IsNumber ${bucksize})
    if [[ -z ${bucksize} ]] || [[ ${isn} -ne 0 ]];then
        bucksize=8
    fi
    Msg "${BLUE}请输入步长(默认为${RESET}${YELLOW}2${RESET}${BLUE}): ${RESET}"
    read step
    local isn=$(IsNumber ${step})
    if [[ -z ${step} ]] || [[ ${isn} -ne 0 ]];then
        step=2
    fi
    
    
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${bucksize} ${step} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset isn
    unset op
    unset image
    unset bucksize
    unset step
    unset save
    unset ret
}

function filter_stylization(){
    local op='STYLIZATION'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入邻域大小[1-200](默认为${RESET}${YELLOW}60${RESET}${BLUE}): ${RESET}"
    read sigma_s
    local isn=$(IsNumber ${sigma_s})
    if [[ -z ${sigma_s} ]] || [[ ${isn} -ne 0 ]];then
        sigma_s=60
    fi
    
    Msg "${BLUE}请输入不同颜色的平均系数[0-1](默认为${RESET}${YELLOW}0.6${RESET}${BLUE}): ${RESET}"
    read sigma_r
    if [[ -z ${sigma_r} ]];then
        sigma_r=0.6
    fi
    if [[ ${sigma_r} -lt 0 ]]&&[[${sigma_r} -gt 1 ]];then
        sigma_r=0.6
    fi
    
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${sigma_s} ${sigma_r} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset sigma_s
    unset sigma_r
    unset save
    unset ret
}

function filter_glass(){
    local op='GLASS'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入混乱系数[0-1](默认为${RESET}${YELLOW}0.1${RESET}${BLUE}): ${RESET}"
    read coef
    if [[ -z ${coef} ]];then
        coef=0.1
    fi
    if [[ ${coef} -lt 0 ]]&&[[ ${coef} -gt 1 ]];then
        coef=0.1
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${coef} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset coef
    unset save
    unset ret
}

function filter_mask(){
    local op='MASK'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    
    Msg "${BLUE}请输入混乱系数[0-1](默认为${RESET}${YELLOW}0.1${RESET}${BLUE}): ${RESET}"
    read coef
    if [[ -z ${coef} ]];then
        coef=0.1
    fi
    if [[ ${coef} -lt 0 ]]&&[[ ${coef} -gt 1 ]];then
        coef=0.1
    fi
    
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${coef} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset coef
    unset save
    unset ret
}

function filter_cartoon(){
    local op='CARTOON'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入双边滤波数目(默认为${RESET}${YELLOW}7${RESET}${BLUE}): ${RESET}"
    read fnum
    local isn=$(IsNumber ${fnum})
    if [[ -z ${fnum} ]] || [[ ${isn} -ne 0 ]];then
        fnum=7
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${fnum} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset fnum
    unset save
    unset ret
}

function filter_monochrome(){
    local op='MONOCHROME'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入灰度阈值(默认为${RESET}${YELLOW}80${RESET}${BLUE}): ${RESET}"
    read thresh
    local isn=$(IsNumber ${thresh})
    if [[ -z ${thresh} ]] || [[ ${isn} -ne 0 ]];then
        thresh=80
    fi
    Msg "${BLUE}请选择黑字白底(True)还是黑底白字(False)(默认为${RESET}${YELLOW}True${RESET}${BLUE}): ${RESET}"
    read flag
    if [[ -z ${flag} ]];then
        flag="True"
    fi

    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${thresh} ${flag} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset thresh
    unset flag
    unset save
    unset ret
}

function remove_background(){
    local op='REMOVEBG'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset save
    unset ret
}

function image_matting(){
    local op='MATTING'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset save
    unset ret
}

function change_background_color(){
    local op='CHANGEBG'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    
    Msg "${BLUE}请输入颜色R值(默认为${RESET}${YELLOW}240${RESET}${BLUE}): ${RESET}"
    read R
    local isn=$(IsNumber ${R})
    if [[ -z ${R} ]] || [[ ${isn} -ne 0 ]];then
        R=240
    fi
    Msg "${BLUE}请输入颜色B值(默认为${RESET}${YELLOW}167${RESET}${BLUE}): ${RESET}"
    read B
    local isn=$(IsNumber ${B})
    if [[ -z ${B} ]] || [[ ${isn} -ne 0 ]];then
        B=167
    fi
    Msg "${BLUE}请输入颜色G值(默认为${RESET}${YELLOW}2${RESET}${BLUE}): ${RESET}"
    read G
    local isn=$(IsNumber ${G})
    if [[ -z ${G} ]] || [[ ${isn} -ne 0 ]];then
        G=2
    fi


    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${R} ${B} ${G} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset isn
    unset op
    unset image
    unset R
    unset B
    unset G
    unset save
    unset ret
}

function remove_shadow(){
    local op='DESHADOWING'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入对象明暗度[0,1](默认为${RESET}${YELLOW}0${RESET}${BLUE}): ${RESET}"
    read M
    local isn=$(IsNumber ${M})
    if [[ -z ${M} ]] || [[ ${isn} -ne 0 ]];then
        M=0
    fi
    Msg "${BLUE}请输入过滤窗口大小(默认为${RESET}${YELLOW}15${RESET}${BLUE}): ${RESET}"
    read N
    local isn=$(IsNumber ${N})
    if [[ -z ${N} ]] || [[ ${isn} -ne 0 ]];then
        N=15
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${M} ${N} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset M
    unset N
    unset save
    unset ret
}

function image_rectification(){
    local op='RECTIFICATION'

    Msg "${BLUE}请输入图片完整路径(有明显边界): ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset save
    unset ret
}

function image_correct(){
    local op='CORRECT'

    Msg "${BLUE}请输入图片完整路径(无明显边界): ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset save
    unset ret
}

function image_clahe(){
    local op='CLAHE'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset save
    unset ret
}

function image_hist(){
    local op='HIST'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset save
    unset ret
}

function image_log(){
    local op='LOG'

    Msg "${BLUE}请输入图片完整路径: ${RESET}"
    read image
    if [[ -z ${image} ]];then
        error "参数为空!"
        return 1
    fi
    local ism=$(IsImage ${image})
    if [[ ${ism} -ne 1 ]];then
        error "无效图片!"
        return 1
    fi
    Msg "${BLUE}请输入要保存的路径(默认为${RESET}${YELLOW}${SAVE_PATH}${RESET}${BLUE}): ${RESET}"
    read save
    if [[ -z ${save} ]] ||  [[ ! -d ${save} ]];then
        save="${SAVE_PATH}"
    fi
    tip "请稍候，正在生成中……"
    local ret=$(python3 ${ENTRY_API} ${op} ${image} ${save})
    if [[ ${ret} =~ "True" ]];then
        success "生成完成!"
    else
        error "生成失败!"
    fi
    unset ism
    unset op
    unset image
    unset save
    unset ret
}






















__api_init__

